package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

type OrderShippingTracking struct {
	ID         string `json:"id" gorm:"column:id;type:uint;size:64;comment:唯一ID;primaryKey"`
	OutTradeNo string `gorm:"column:out_trade_no;type:varchar(50);uniqueIndex:uk_out_trade_no;default:null;comment:订单号;" json:"out_trade_no"`
	ExpressCom string `json:"express_com" gorm:"column:express_com;type:varchar(50);comment:快递公司"`
	ExpressNum string `json:"express_num" gorm:"column:express_num;type:varchar(50);comment:快递单号"`
	Data       string `json:"data" gorm:"column:data;type:text;comment:轨迹"`
	CreatedAt  int64  `gorm:"column:created_at;autoCreateTime;type:int;size:64;comment:创建时间" json:"created_at"`
}

// TableName 表名称
func (m *OrderShippingTracking) TableName() string {
	return "order_shipping_tracking"
}

// BeforeCreate 自增id
func (m *OrderShippingTracking) BeforeCreate(tx *gorm.DB) (err error) {
	if m.ID != "" {
		return nil
	}
	// 用户id为空时，自动添加用户id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	m.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &OrderShippingTracking{})
}
